﻿using otis.entities.products;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上有介绍

namespace otis.views.product
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class ProductStyle : Page
    {
        private List<StyleBigType> styleBigTypes = StyleBigTypeHelper.InitStyleBigType();
        private List<StyleAttachBigType> styleAttachBigTypes = new List<StyleAttachBigType>();
        private entities.products.Product pageRequestValue = null;
        private List<StyleDetails> styleDetails = null;

        public ProductStyle()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //base.OnNavigatedTo(e);
            //接收参数
            this.pageRequestValue = e.Parameter as entities.products.Product;
            if (this.pageRequestValue == null)
            {
                //
                Frame.GoBack();
            }
            this.btnCampaignName.Content = this.pageRequestValue.Campaign.Name;

            //
            this.styleAttachBigTypes = StyleAttachBigTypeHelper.InitStyleAttachBigType(styleBigTypes);

            //
            this.lvStyleAttachBigType.ItemsSource = this.styleAttachBigTypes;
        }

        private void btnCampaignName_Click(object sender, RoutedEventArgs e)
        {
            Frame.GoBack();
        }

        private void lvCampaign_ItemClick(object sender, ItemClickEventArgs e)
        {
            var item = e.ClickedItem as StyleAttachBigType;
            if (item == null)
            {
                this.styleDetails = null;
            }
            else {
                this.styleDetails = StyleDetailsHelper.InitStyleDetails(CampaignHelper.InitCampaign(), this.styleAttachBigTypes);
                this.styleDetails = (from p in this.styleDetails where p.StyleAttachBigType.Name.Equals(item.Name) select p).ToList<StyleDetails>();
            }


            this.lvStyle.ItemsSource = this.styleDetails;
        }
    }
}
